#include "in.h"

int MDBInsert( struct MemTable *table , void *insert_record )
{
	char			*record_dataunit = NULL ;
	char			*record_data = NULL ;
	
	int			nret = 0 ;
	
	CreateCurrentTransaction( table->db );
	
	record_dataunit = GetUnusedUncommitRecordDataUnit( table ) ;
	record_data = MDB_RECORD_DATAUNIT_TO_DATA(record_dataunit) ;
	TRACE_PRINTF( "GetUnusedUncommitRecordDataUnit return record_dataunit[%p][%p]\n" , record_dataunit , record_data );
	memcpy( record_data , insert_record , table->record_size );
	
	AppendInsertUndoDataToCurrentTransaction( table , record_dataunit );
	
	nret = ExecuteCurrentTransaction( table->db ) ;
	if( nret )
	{
		CancelCurrentTransaction( table->db );
	}
	
	DestroyCurrentTransaction( table->db );
	
	return nret;
}

